S3 & S4 object

클래스(S3)
a<-c(xleft=10, ybottom=7, xright=15, ytop=9)
class(a)<-"rectangle" # class 'rectangle'
b<-list(center=c(10, 5), radius=5)
class(b)<-"circle" # class 'circle'
#
area<-function(x, ...){
UseMethod("area", x)
}
area.rectangle<-function(x, ...){
as.numeric((x["xright"]-x["xleft"])*(x["ytop"]-x["ybottom"]))
}
area.circle<-function(x, ...){
pi*x$radius^2
}
Generic Function area()함수가 rectangle 객체를 받으면, area.rectangle() 메서드가 실행되고,
circle 객체를 받으면, area.circle 객체가 실행된다.
methods("area") # generic function "area"
getS3method("area", "circle") # method

function(x, ...){

  pi*x$radius^2

}

<bytecode: 0x1239da658>

#
new_circle<-function(x, y, r){
circle<-list(center=c(x, y), radius=r)
class(circle<-"circle"
circle
}